import toml
import datetime


def build_version():
    """生成版本信息文件"""
    with open('pyproject.toml', 'r', encoding='utf-8') as f:
        data = toml.load(f)
        version = data['project']['version']
        author = data['project']['authors'][0]['name']
        build_time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")

    with open('src/version.py', 'w', encoding='utf-8') as f:
        f.write(f'VERSION = "{version}"\n')
        f.write(f'AUTHOR = "{author}"\n')
        f.write(f'DATETIME = "{build_time}"\n')


build_version()
